#include "footmarklayout.h"


#include "footmarklistview.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QFontDatabase>
#include <QFileInfo>
#include <QDebug>



namespace kepen {
namespace core {


FootmarkLayout::FootmarkLayout(QWidget *parent,kepen::core::MapObject* map,KeSysSetting *sys)
    : QStackedLayout{parent}
    ,mapSurface{map}
    ,mSysConfig{sys}
    ,db{NULL}
    ,dao {NULL}
{

    setSpacing(0);
    setContentsMargins(0, 0, 0, 0);
    setAlignment(Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop);



    FootmarkListView *listView = new FootmarkListView(parent,sys,this);

    addWidget(listView);

    {

        sqlite3 * _db = sys->configSQLite()->getSQLite3Catch();
        if(_db){
            int status ;
            char _tableName[32];
            memset(_tableName,0,32);
            status = sys->tableNameFootMark(_tableName);

            if(0==status)
            {
                kepen::kemod::KeFootmarkDao *_dao = new  kepen::kemod::KeFootmarkDao();

                _dao->setDbSource(_db);
                _dao->setTableName(_tableName);
                _dao->crateIfNotExists();

                dao = _dao;
                this->db = _db;

                listView->setDataSource(map,_dao);
            }

        }

    }




    QPushButton*btnClose =  listView->getBtnClose();

    connect(btnClose, &QPushButton::clicked, [=]() {
        Q_EMIT onTabLayoutClosed(this);
    });


    int n = listView->gotoPage(1);
    if(n>0)
    {
        listView->focusTableView();
    }


}

FootmarkLayout::~FootmarkLayout()
{
    if(dao){
        delete dao;
        dao = NULL;
    }
}



}
}
